package com.lfy.modules.letter.domain.builder;

import com.lfy.modules.blog.mapper.UserEntityMapper;
import com.lfy.modules.common.domain.entity.UserEntity;
import com.lfy.modules.common.intercept.AuthHandlerInterceptor;
import com.lfy.modules.common.utils.RequestUtil;
import com.lfy.modules.letter.domain.SiteLetterEntity;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;


public class Letter {

    public static SiteLetterEntity choiceType(Integer type){
        SiteLetterEntity siteLetterEntity = new SiteLetterEntity();
        siteLetterEntity.setMsgType(type);
        if(LetterEnum.LetterType.SITE_SEND.getCode().equals(type)){
            UserEntity user = AuthHandlerInterceptor.authLocal.get();
            siteLetterEntity.setSenderId(user.getId());
            siteLetterEntity.setSenderName(user.getName());
        }else {
            siteLetterEntity.setSenderId(0L);
            siteLetterEntity.setSenderName(LetterEnum.LetterType.SYS_SEND.getMsg());
        }
        return siteLetterEntity;

    }
    public static SiteLetterEntity builder(Integer type,String  subject,String content,Long receiverId,Integer isEmailSend){
        SiteLetterEntity siteLetterEntity = choiceType(type);
        siteLetterEntity.setSubject(subject);
        siteLetterEntity.setContent(content);
        siteLetterEntity.setReceiveId(receiverId);
        siteLetterEntity.setIsSendEmail(isEmailSend);
        siteLetterEntity.setIsRead(LetterEnum.ReadType.UN_READ.getCode());
        return siteLetterEntity;
    }
    public static String builderCommentContent(String content,String name,String toName,String email,String toEmail){
        StringBuffer sb = new StringBuffer();
        if(StringUtils.isNotEmpty(name)){
            sb.append("评论人：").append(name).append("<br>");
        }

        if(StringUtils.isNotEmpty(email)){
            sb.append("评论人邮箱：").append(email).append("<br>");
        }

        if(StringUtils.isNotEmpty(toName)){
            sb.append("回复人：").append(toName).append("<br>");
        }

        if(StringUtils.isNotEmpty(toEmail)){
            sb.append("回复人邮箱：").append(toEmail).append("<br>");
        }
        sb.append("评论内容:").append(content);
        return sb.toString();
    }
    public static String builderRemoveArticleContent(String content){
        return "原因："+content;
    }
    public static String builderChangeRoleContent(String content){
        return "你的身份以变更为 【"+content+"】";
    }
    public static String builderShareFIleContent(String content,String ip){

        String place = RequestUtil.getPlace(ip);

        return "你分享的文件【"+content+"】被提取了"+"<br>"+"提取ip："+ip+"<br>"+"提取地点："+place+"<br>"+"请注意保护好您的隐私!如遇非法提取，请在站长反馈中提交您遇到的Bug";
    }


}
